home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Gold Collection
/
Software Vault - The Gold Collection (American Databankers) (1993).ISO
/
cdr25
/
memsz130.zip
/
OBJECT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-03-14
|
14KB
|
415 lines
/*************************************************************** OBJECT.C
* *
* Object Processor Definitions *
* *
************************************************************************/
#define INCL_WIN
#define INCL_GPI
#include <os2.h>
#include <stdlib.h>
#include "object.h"
#define TRUE 1
#define FALSE 0
#define NOT !
#define OR ||
#define AND &&
/************************************************************************
* *
* Initialize PM Environment at program start *
* *
************************************************************************/
VOID Object
(
HAB *phAB,
HMQ *phMQ,
ULONG flStyle,
HELPINIT *pHelpInit,
HWND *phwndHelp,
HWND hwndOwner,
SHORT idWindow,
PCLASS pClass,
PCHAR pszTitle
)
{
/***********************************************************************
* Local Declarations *
***********************************************************************/
HAB hAB ;
HMQ hMQ ;
HWND hwnd ;
/***********************************************************************
* Initialize environment. *
***********************************************************************/
ObjInitialize
(
phAB ? phAB : &hAB,
phMQ ? phMQ : &hMQ,
flStyle,
pHelpInit,
phwndHelp
) ;
/***********************************************************************
* Create the object. *
***********************************************************************/
hwnd = ObjCreateObject ( hwndOwner, idWindow,
pClass, pszTitle, *phwndHelp ) ;
/***********************************************************************
* Go execute the object. Destroy it and clean up when done. *
***********************************************************************/
ObjExecuteAll ( phAB ? *phAB : hAB ) ;
ObjDestroy ( hwnd ) ;
ObjCleanup ( phAB ? *phAB : hAB, phMQ ? *phMQ : hMQ, *phwndHelp ) ;
}
/************************************************************************
* *
* Initialize PM Environment at program start *
* *
************************************************************************/
VOID ObjInitialize
(
HAB *phAB,
HMQ *phMQ,
ULONG flStyle,
HELPINIT *pHelpInit,
HWND *phwndHelp
)
{
/***********************************************************************
* Initialize PM mode and create the application message queue. *
***********************************************************************/
*phAB = WinInitialize ( 0 ) ;
*phMQ = WinCreateMsgQueue ( *phAB, 0 ) ;
/***********************************************************************
* Register the general object class. *
***********************************************************************/
WinRegisterClass
(
*phAB,
CLASS_OBJECT,
ObjMessageProcessor,
flStyle,
sizeof(PVOID)
) ;
/***********************************************************************
* If help instance to be set up, do it. *
***********************************************************************/
if ( pHelpInit )
{
*phwndHelp = WinCreateHelpInstance ( *phAB, pHelpInit ) ;
if ( *phwndHelp == NULL )
{
WinMessageBox ( HWND_DESKTOP, HWND_DESKTOP,
"ERROR: Unable to create help instance.",
"Window", 0, MB_ENTER ) ;
}
}
}
/************************************************************************
* *
* Create an Object *
* *
************************************************************************/
HWND ObjCreateObject
(
HWND hwndOwner,
SHORT idWindow,
PCLASS pClass,
PCHAR szTitle,
HWND hwndHelp
)
{
/***********************************************************************
* Local Declarations *
***********************************************************************/
FRAMECDATA fcdata ;
HWND hwndClient ;
HWND hwndFrame = hwndOwner ;
/***********************************************************************
* If called for, create a frame window. Return if unable to do so. *
***********************************************************************/
if ( pClass->fFrame )
{
fcdata.cb = sizeof(fcdata) ;
fcdata.flCreateFlags = pClass->FrameData.flCreateFlags ;
fcdata.hmodResources = pClass->FrameData.hmodResources ;
fcdata.idResources = pClass->FrameData.idResources ;
hwndFrame = WinCreateWindow ( hwndOwner, WC_FRAME, "",
pClass->FrameData.flStyle, 0, 0, 0, 0, hwndOwner, HWND_TOP,
idWindow, &fcdata, NULL ) ;
if ( hwndFrame == NULL )
{
return ( NULL ) ;
}
hwndOwner = hwndFrame ;
idWindow = FID_CLIENT ;
if ( szTitle )
{
WinSetWindowText ( pClass->fFrame ? hwndFrame : hwndClient, szTitle ) ;
}
}
/***********************************************************************
* Create client window. If this fails, destroy frame and return. *
***********************************************************************/
hwndClient = WinCreateWindow ( hwndOwner, CLASS_OBJECT, "",
pClass->flStyle, 0, 0, 0, 0, hwndOwner, HWND_BOTTOM,
idWindow, pClass, NULL ) ;
if ( hwndClient == NULL )
{
if ( pClass->fFrame )
{
WinDestroyWindow ( hwndFrame ) ;
}
return ( NULL ) ;
}
/***********************************************************************
* Associate the help instance with the frame window. *
***********************************************************************/
WinSetWindowUShort ( pClass->fFrame ? hwndFrame : hwndClient, QWS_ID, idWindow ) ;
if ( hwndHelp )
{
WinAssociateHelpInstance ( hwndHelp, pClass->fFrame ? hwndFrame : hwndClient ) ;
}
/***********************************************************************
* Return handle to frame. *
***********************************************************************/
return ( pClass->fFrame ? hwndFrame : hwndClient ) ;
}
/************************************************************************
* *
* Execute all Objects *
* *
************************************************************************/
VOID ObjExecuteAll ( HAB hAB )
{
/***********************************************************************
* Local Declarations *
***********************************************************************/
QMSG qmsg ;
/***********************************************************************
* Wait for and process messages to the window's queue. Terminate *
* when the WM_QUIT message is received. *
***********************************************************************/
while ( WinGetMsg ( hAB, &qmsg, NULL, 0, 0 ) )
{
WinDispatchMsg ( hAB, &qmsg ) ;
}
}
/************************************************************************
* *
* Destroy a generalized Object *
* *
************************************************************************/
VOID ObjDestroy ( HWND hwnd )
{
/***********************************************************************
* Destroy window. *
***********************************************************************/
WinDestroyWindow ( hwnd ) ;
}
/************************************************************************
* *
* Clean up PM Environment prior to program completion. *
* *
************************************************************************/
VOID ObjCleanup ( HAB hAB, HMQ hMQ, HWND hwndHelp )
{
/***********************************************************************
* If help instance has been created, get rid of it. *
***********************************************************************/
if ( hwndHelp )
{
WinDestroyHelpInstance ( hwndHelp ) ;
}
/***********************************************************************
* Discard all that was requested of the system and terminate. *
***********************************************************************/
WinDestroyMsgQueue ( hMQ ) ;
WinTerminate ( hAB ) ;
}
/************************************************************************
* *
* General Object Procedure - Process messages to object *
* *
************************************************************************/
MRESULT EXPENTRY ObjMessageProcessor
(
HWND hwnd,
USHORT msg,
MPARAM mp1,
MPARAM mp2
)
{
/***********************************************************************
* Declarations *
***********************************************************************/
USHORT cNumberLeft ;
MRESULT mr ;
PCLASS pClass ;
PVOID pData ;
PMETHOD pMethod ;
POBJECT pObject ;
SEL selData ;
SEL selObject ;
/***********************************************************************
* Perform pre-processing of WM_CREATE message. *
***********************************************************************/
if ( msg == WM_CREATE )
{
pClass = (PCLASS) PVOIDFROMMP ( mp1 ) ;
DosAllocSeg ( sizeof(OBJECT), &selObject, SEG_NONSHARED ) ;
DosAllocSeg ( pClass->cDataSize, &selData, SEG_NONSHARED ) ;
pObject = MAKEP ( selObject, 0 ) ;
pObject->selObject = selObject ;
pObject->selData = selData ;
pObject->pClass = pClass ;
WinSetWindowPtr ( hwnd, 0, pObject ) ;
}
/***********************************************************************
* Get object's class information and private data pointer. *
***********************************************************************/
pObject = (POBJECT) WinQueryWindowPtr ( hwnd, 0 ) ;
pData = MAKEP ( pObject->selData, 0 ) ;
pClass = pObject->pClass ;
/***********************************************************************
* Process messages according to object's class method table. *
***********************************************************************/
pMethod = pClass->pMethods ;
cNumberLeft = pClass->cMethods ;
while ( ( cNumberLeft ) AND ( pMethod->Action != msg ) )
{
pMethod ++ ;
cNumberLeft -- ;
}
if ( cNumberLeft )
{
mr = pMethod->pFunction ( hwnd, msg, mp1, mp2, pData ) ;
}
else
{
mr = pClass->BaseObjectProcessor ( hwnd, msg, mp1, mp2 ) ;
}
/***********************************************************************
* Perform post-processing of WM_DESTROY message. *
***********************************************************************/
if ( msg == WM_DESTROY )
{
DosFreeSeg ( pObject->selData ) ;
DosFreeSeg ( pObject->selObject ) ;
}
/***********************************************************************
* Return result from message processor. *
***********************************************************************/
return ( mr ) ;
}
/************************************************************************
* *
* Generalized Message Processor *
* *
************************************************************************/
MRESULT EXPENTRY GeneralMessageProcessor
(
HWND hwnd,
USHORT msg,
MPARAM mp1,
MPARAM mp2,
PMETHOD pMethods,
SHORT cMethods,
MRESULT (EXPENTRY *pDefaultMessageProcessor) (HWND,USHORT,MPARAM,MPARAM),
PVOID pData
)
{
/***********************************************************************
* Search class method table for message to be processed. *
***********************************************************************/
while ( ( cMethods ) AND ( pMethods->Action != msg ) )
{
pMethods ++ ;
cMethods -- ;
}
/***********************************************************************
* If message was found, return through specified processing function. *
***********************************************************************/
if ( cMethods )
{
return ( pMethods->pFunction ( hwnd, msg, mp1, mp2, pData ) ) ;
}
/***********************************************************************
* If not, return through the default message processing function. *
***********************************************************************/
return ( pDefaultMessageProcessor ( hwnd, msg, mp1, mp2 ) ) ;
}